<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class GroupCourseOrder extends Model
{

    const STATUS_PENDING = 1; //  待核销
    const STATUS_USED = 2; //  已核销
    const STATUS_CANCELED = 3; //  已取消

    protected $fillable = [
        'tenant_id',
        'user_id',
        'group_course_id',
        'order_sn',
        'transaction_id',
        'openid',
        'body',
        'total_fee',
        'is_paid',
        'paid_time',
        'status',
        'course_date',
        'course_start_time',
        'course_end_time',
        'audit_user_id',
        'audit_time',
        'cancel_time',
        'cancel_reason',
        'audit_qrcode',
        'audit_qrcode_weapp',
    ];

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function groupCourse()
    {
        return $this->belongsTo(GroupCourse::class);
    }

    public function tenant()
    {
        return $this->belongsTo(Tenant::class);
    }

    /**
     * 生成订单号
     * @return string
     */
    public static function generateOrderNo($prefix = '')
    {
        return $prefix . date('YmdHis') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
    }
}
